<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="work.atpgroup.entity.WebPage,work.atpgroup.entity.User" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <title>资源管理页面</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
    <link rel="stylesheet" href="https://www.layuicdn.com/layui-v2.7.6/css/layui.css"/>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.min.js" integrity="sha384-IDwe1+LCz02ROU9k972gdyvl+AESN10+x7tBKgc9I5HFtuNz0wWnPclzo6p9vxnk" crossorigin="anonymous"></script>
    <script src="https://code.jquery.com/jquery-3.6.1.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/3.0.5/vue.global.js"></script>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/enroll.css">
    <style>
        body{
            background: azure;
        }
        .admin-panel{
            margin-top: 30px;
            min-height: 600px;
        }
        .panel{
            border: 1px solid #f0f7fa;
        }
        .panel > *{
            font-size: 16px;
        }
        .panel > div{
            padding: 0 5px;
            border: 1px solid ;
        }
        .context{
            border-left: 2px solid lightpink;
        }
        .context,.panel{
            min-height: 600px;
        }

        .webpage >*{
            text-align: center;
        }
        .create > a{
            text-decoration: none;
        }

        .resource{
            padding: 5px;
            border: 1px solid black;
            display: flow-root;
        }
        .resource >*{
            float: left;

        }
        .resource:after{
            content: " ";
            clear: both;
        }
        .delete{
            text-align: center;
        }
        .add{
            display: flow-root;
        }
        .add:after{
            content: " ";
            clear: both;
        }
        .add a{
            float: right;
            font-size: 32px;
        }
    </style>
</head>
<body>
<jsp:include page="../share/enroll.jsp"/>
<div class="container admin-panel">
    <div class="row admin">
        <jsp:include page="../share/admin_panel.jsp"/>
        <div class="col-8 bg-light context">
            <div class="add">
                <a href="${pageContext.request.contextPath}/resource_upload/page">+</a>
            </div>
            <c:if test="${resources!=null&&resources.size()>0}">
                <c:forEach items="${resources}" var="resource">
                    <div class="resource">
                        <div class="info col-6">
                            <div class="path">资源名: ${resource.path}</div>
                            <div class="date">上传日期: ${resource.date}</div>
                        </div>
                        <div class="privateLink col-2"><a href="${pageContext.request.contextPath}/resources/${resource.resourceId}">私有链接</a></div>
                        <div class="publicLink col-2"><a href="${pageContext.request.contextPath}/resource_bed/${resource.path}">公开链接</a></div>
                        <div class="delete col-2"><a class="layui-btn layui-btn-danger layui-btn-mini" onclick="deleteResource(${resource.resourceId})">删除</a></div>
                    </div>
                </c:forEach>
            </c:if>
        </div>
    </div>
</div>
</body>
<script>
    function confirmDelete() {
        var msg = "您确定要删除吗？";
        return confirm(msg) === true;
    }
    function deleteResource(id) {
        if(confirmDelete()===true){
            $.ajax({
                async: false,
                type: "POST",
                url:'${pageContext.request.contextPath}/admin/static-file-list/delete/'+id,
                contentType : "application/x-www-form-urlencoded; charset=utf-8",
                dataType: "text",
                complete:function () {
                    window.location.reload();
                }
            })
        }
    }
</script>
</html>